/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.techopropio.bfh.controller;

import com.techopropio.bfh.service.SolicitudDao;
import com.techopropio.bfh.service.SolicitudDaoSim;
import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 *
 * @author Williams
 */
@WebServlet(name = "evaluadorController01", urlPatterns = {"/Evaluador.htm"})
public class EvaluadorController01 extends HttpServlet {

    private SolicitudDao solicitudDao;

    @Override
    public void init() throws ServletException {
        solicitudDao = new SolicitudDaoSim();
    }

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        if (req.getSession().getAttribute("usuario") == null) {
            resp.sendRedirect("/BonFamHab2/welcome.htm");
        }
        req.getSession().setAttribute("list", solicitudDao.listarSolicitudes());
        getServletContext().getRequestDispatcher("/views/Evaluador01.jsp").forward(req, resp);
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        if (req.getParameter("evaluar") != null) {
            solicitudDao.updatePuntajes();
            resp.sendRedirect("/BonFamHab2/Puntajes.htm");
        } else if (req.getParameter("revisar") != null) {
            if (req.getParameter("A") == null) {
                resp.sendRedirect("/BonFamHab2/Evaluador.htm");
            } else {
                req.getSession().setAttribute("dni", req.getParameter("A"));
                resp.sendRedirect("/BonFamHab2/Revisar.htm");
            }
        } else {
            req.getSession().removeAttribute("usuario");
            resp.sendRedirect("/BonFamHab2/welcome.htm");
        }
    }
}
